package hb.software.course.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import hb.software.course.entity.Course;
import hb.software.course.service.CourseManager;
import web.GenericController;

@RestController
@RequestMapping("/course")
public class CourseController extends GenericController<Course, Long, CourseManager> {
	CourseManager courseManager;

	
	@Autowired
	public void setStudentManager(CourseManager studentManager) {
		this.courseManager = studentManager;
		this.manager = this.courseManager;
	}
	@GetMapping("/findall/{page}/{size}")
	public Page<Course> findall(@PathVariable("page")Integer page,@PathVariable("size")Integer size){
		Pageable pageable=PageRequest.of(page-1,size);
		return courseManager.findAll(pageable);
	}

	@PostMapping("/save")
	public Course save(@RequestBody Course course){
		Course result=courseManager.save(course);
		return result ;
	}
	@GetMapping("/findbyid/{id}")
	public Course findById(@PathVariable("id")Long id){
		return courseManager.findById(id);
	}
	
	@DeleteMapping("/delete/{id}")
	public void delete(@PathVariable("id")Long id) {
		courseManager.delete(id);
	}
	@PutMapping("/updata")
	public Course updata(@RequestBody Course course){
		Course result=courseManager.save(course);
		return result ;
	}
}

